package model.characters;

import java.awt.Rectangle;

import model.GameContext;


public class NPC extends CharacterDecorator {

	public Rectangle visibility;

	public NPC(CharacterInterface character) {
		super(character);
		visibility = new Rectangle(800,120);
	}

	@Override
	public void update() {
		//usado apra atualizar a barra de vida do NPC
		setLife(super.getLife());
		if(!character.isDead()){
			CharacterInterface player = GameContext.getCurrentStage().getPlayer();

			if(getDirection()>0)
				visibility.x = getRegion().x-320;
			else
				visibility.x = getRegion().x-450;

			visibility.y = getRegion().y-30;

			if(player.getRegion().intersects(visibility)){
				character.setDirection((player.getRegion().x<getRegion().x)?
						GameContext.LEFT_DIRECTION:
							GameContext.RIGHT_DIRECTION);
				setShooting(true);
			}
			else
				setShooting(false);
		}else{
			setShooting(false);
		}

		if(!isWalkingL() && !isWalkingR() && (!isRunning() || (isRunning()&&(!isWalkingL() && !isWalkingR()))) && !isJumping() && !isFalling() && !isLowered())
			setStateCode(getDirection()); //IDLE

		character.update();
	}

}
